<?php
namespace app\wap\controller;

class Doc extends Base
{
    public function index($cate ="")
    {
        $category_ch = empty($cate) ? 'nbaluxiang' : $cate;
        $category =_db('category',[], false)->where('pinyin' , $category_ch)->find();
        $doclist = _db('article_doc' , [] , false)->where('category_id' , $category['id'])->order('create_time desc')->paginate(20);
        return $this->fetchHtml('index' , [
            'web_title'=> $category['web_title'] . '-看球吧',
            'web_kw'   => $category['web_kw'],
            'web_desc' => $category['web_desc']. '尽在看球吧',
            'category' => $category,
            'doclist' => $doclist
        ]);
    }

    public function info($id = 0){
        $id = intval($id);
        if($id <= 0){
            $this->redirect('index');
            exit;
        }
        $info = _db('article_doc' , [] , false)->where('id' , $id)->find();
        $category = _db('category',[], false)->where('id' , $info['category_id'])->find();
        $pre = _db('article_doc' , [] , false)->where('category_id' , $category['id'])->where('id' ,'<', $info['id'])->order('create_time desc')->find();
        $next = _db('article_doc' , [] , false)->where('category_id' , $category['id'])->where('id' ,'>', $info['id'])->order('create_time desc')->find();
        $aboutlist = _db('article_doc' , [] , false)->where('category_id' , $info['category_id'])->limit(10)->select();
        $webtitle = $info['title'];
        return $this->fetchHtml('info',[
            'web_title' =>  $webtitle . ' - ' . $category['title'] . ' -看球吧',
            'web_kw' => $webtitle,
            'web_desc' => $webtitle,
            'info' => $info,
            'category' => $category,
            'pre' => $pre,
            'next' => $next,
            'aboutlist' => $aboutlist
        ]);
    }

}
